var arr = [1, [[2, 3], 4], [5, 6]];

var flat = function* (a) {
  var length = a.length;
  for (var i = 0; i < length; i++) {
    var item = a[i];
    if (typeof item !== 'number') {
      yield* flat(item);
    } else {
      yield item;
    }
  }
};

for (let f of flat(arr)) {
  console.log(f);
}

var myIterable = {};
myIterable[Symbol.iterator] = function* () {
  yield 1;
  yield 2;
  yield 3;
};

console.log([...myIterable]) // [1, 2, 3]

function* f() {
    for(var i = 0; true; i++) {
      var reset = yield i;
      if(reset) { i = -1; }
    }
  }
  
  var g = f();
  
 console.log(g.next())  // { value: 0, done: false }
  console.log(g.next()) // { value: 1, done: false }
  console.log(g.next(true)) // { value: 0, done: false }

  function* foo(x) {
    var y = 2 * (yield (x + 1));
    var z = yield (y / 3);
    return (x + y + z);
  }
  
  var a = foo(5);
  console.log(a.next()) // Object{value:6, done:false}
  console.log(a.next()) // Object{value:NaN, done:false}
  console.log(a.next()) // Object{value:NaN, done:true}
  
  var b = foo(5);
  console.log(b.next()) // { value:6, done:false }
  console.log(b.next(12)) // { value:8, done:false }
  console.log(b.next(13)) // { value:42, done:true }


// function* objectEntries(obj) {
//     let propKeys = Reflect.ownKeys(obj);
  
//     for (let propKey of propKeys) {
//         yield [propKey, obj[propKey]];
//     }
// }
  
// let jane = { first: 'Jane', last: 'Doe' };
  
// for (let [key, value] of objectEntries(jane)) {
//     console.log(`${key}: ${value}`);
// }

// function* objectEntries() {
//     let propKeys = Object.keys(this);
  
//     for (let propKey of propKeys) {
//       yield [propKey, this[propKey]];
//     }
// }
  
// let jane = { first: 'Jane', last: 'Doe' };

// jane[Symbol.iterator] = objectEntries;

// for (let [key, value] of jane) {
//     console.log(`${key}: ${value}`);
// }

function* getVal(x) {
    yield x * 2;
    yield x * 3;
}

function* numbers () {
    const gv = getVal(2);
    yield gv.next()
    yield gv.next()
    return 3
    yield 4
}
console.log([...numbers()]);